﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using PBDesk.Utilities;
using Umbraco.Cms.Web.Model;
using Umbraco.Cms.Web;

namespace PBDesk.com.WebSite.Helpers
{
    public class MyHelper
    {
        private const string DEFAULT_THEME = "Rambling";
        public static string GetTheme()
        {
            string theme = DEFAULT_THEME;
            bool themeEnabled = false;
            if (bool.TryParse(ConfigurationManager.AppSettings["ThemeEnabled"] ?? "false", out themeEnabled) && themeEnabled == true)
            {
                theme = HttpContext.Current.Request.QueryString["tag"];
                if (theme.IsNullOrEmpty())
                {
                    theme = ConfigurationManager.AppSettings["Theme"];
                }
                if (theme.IsNullOrEmpty())
                {
                    theme = DEFAULT_THEME;
                }
            }
            return theme;
        }

        public static string GetBannerColumnStyle(int colCount)
        {
            return (colCount == 1) ? "columns100" : (colCount == 2 ? "columns5050" : "columns");
        }

        public static List<string> GetAllTags(IQueryable<Content> content)
        {
            var tagEntries = content.ToList().Select(x => x.Field<string>("tagCategories"));
            var uniqueTags = new List<String>();
            foreach (var tags in tagEntries)
            {
                if (!string.IsNullOrWhiteSpace(tags))
                {
                    foreach (var tag in tags.Split(','))
                    {
                        if (uniqueTags.Contains(tag) == false)
                        {
                            uniqueTags.Add(tag);
                        }
                    }

                }

            }
            return uniqueTags;
        }
    }
}